package structures.test;

import java.util.Comparator;
import java.util.PriorityQueue;

public class PriorityQueueDemo {
    public static void main(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        });
        priorityQueue.add(5);
        priorityQueue.add(3);
        priorityQueue.add(6);
        priorityQueue.add(1);
        priorityQueue.add(9);
        priorityQueue.add(2);

        while (!priorityQueue.isEmpty()) {
            for (Integer data : priorityQueue) {
                System.out.print(data + "\t");
            }
            System.out.println("\n-------------");
            System.out.println("-------------取出: " + priorityQueue.poll() + "-------------");
        }

    }
}
